package com.zzptc.mzb.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
     EditText zhanghao;
     EditText mima;
     Button denglu;
     Switch login;
    boolean auto=false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();//实例化案件
        SharedPreferences sh=getSharedPreferences("data",MODE_PRIVATE);
       boolean auto=sh.getBoolean("auto",false);
        event();//处理事件
    }
    private void event() {
        auto=false;
     login.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (buttonView.isChecked()){
                   //Toast.makeText(MainActivity.this,"选中了",Toast.LENGTH_SHORT).show();
                   auto=true;
               }else {
                  //Toast.makeText(MainActivity.this,"没选中",Toast.LENGTH_SHORT).show();
                  auto=false;
               }
          }
        });
        denglu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username=zhanghao.getText().toString().trim();
               String pwd =mima.getText().toString().trim();
                 SharedPreferences sp= getSharedPreferences("data",MODE_PRIVATE);
                 SharedPreferences.Editor edit=sp.edit();
                   if (auto){
                 edit.putString("username",username);
                 edit.putString("pwd",pwd);
                 edit.putBoolean("auto",true);
                 edit.commit();
               }else {

               }

            }
        });
    }

    private void init() {
        zhanghao=findViewById(R.id.zhanghao);
        mima=findViewById(R.id.mima);
        login=findViewById(R.id.login);
        denglu=findViewById(R.id.denglu);
    }
}
